package com.mall.gateway.config;

import com.mall.gateway.fallback.HystrixFallbackHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * 路由配置
 */
@Configuration
public class RouteConfig {
    
    /**
     * 熔断降级路由
     */
    @Bean
    public RouterFunction<ServerResponse> routerFunction(HystrixFallbackHandler hystrixFallbackHandler) {
        return RouterFunctions.route(
                RequestPredicates.path("/fallback")
                        .and(RequestPredicates.accept(MediaType.APPLICATION_JSON)),
                hystrixFallbackHandler
        );
    }
} 